Excel BI - Excel Challenge 837

excel-challenges
excel-formulas
🔰 Extract the numbers and List the numbers where sum of digits = product of digits.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 837

Challenge Description

🔰 Extract the numbers and List the numbers where sum of digits = product of digits.

Solutions

library(tidyverse)
library(readxl)

path = "Excel/800-899/837/837 Product and Sum of Digits are Same.xlsx"
input = read_excel(path, range = "A1:A10")
test  = read_excel(path, range = "B1:B6")

result = input %>%
  mutate(digits = str_remove_all(as.character(Numbers), "\\D"),
         dgt = str_split(digits, ""), 
         sum_digits = map_int(dgt, ~ sum(as.integer(.x))),
         product_digits = map_int(dgt, ~ prod(as.integer(.x)))) %>%
  filter(sum_digits == product_digits) %>%
  mutate(`Answer Expected` = as.integer(digits)) %>%
  select(`Answer Expected`) 

all.equal(result, test)
# [1] TRUE
  • Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Parse the packed text or string structure.
  • Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
  • Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
  • Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd, numpy as np
import os

file_path = "800-899/837/837 Product and Sum of Digits are Same.xlsx"
df = pd.read_excel(file_path, usecols="A", nrows=10)
test = pd.read_excel(file_path, usecols="B", nrows=5)


digits = df.iloc[:,0].astype(str).str.replace(r'\D', '', regex=True)
sum_digits = digits.map(lambda x: sum(map(int, x)))
prod_digits = digits.map(lambda x: np.prod(list(map(int, x))) if x else 0)

result = digits[(sum_digits == prod_digits)].astype(int).reset_index(drop=True).to_frame('Answer Expected')

print(result.equals(test))  # True

The Python version mirrors the same workbook logic with a concise, direct implementation.

Difficulty Level

Easy / Medium

The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.